import React, { Component, Fragment } from "react";
// antd
import { Tag } from "antd";
// table 组件
import TableComponent from "@c/tableData/Index";
import { Task_Status } from "../../constants";

class TaskList extends Component {
    constructor(props){
        super(props);
        this.state = {
            // id
            id: "",
            // flag
            flag: false,
            // 请求参数
            PageNumber: 1,
            PageSize: 10,
            keyWork: "",
            // 表头
            tableConfig: {
                url: "taskRecordList",
                method: "get",
                checkbox: true,
                thead: [
                    { 
                        title: "流程", 
                        dataIndex: "flow_id", 
                        key: "flow_id"
                    },
                    { 
                        title: "提交人", 
                        dataIndex: "executor", 
                        key: "executor"
                    },
                    { 
                        title: "内容", 
                        dataIndex: "task_command", 
                        ellipsis: true,
                        key: "task_command"
                    },
                    { 
                        title: "开始时间", 
                        dataIndex: "created", 
                        key: "created"
                    },
                    { 
                        title: "结束时间", 
                        dataIndex: "end_time", 
                        key: "end_time"
                    },
                    { 
                        title: "日志", 
                        dataIndex: "history_log", 
                        ellipsis: true,
                        key: "history_log"
                    },
                    { 
                        title: "执行状态", 
                        dataIndex: "task_status", 
                        key: "task_status",
                        render: task_status => {
                            let status = Task_Status[task_status]
                            let ccolor = task_status === 2 ? 'red' : 'yellow'
                            if(task_status === 0){ ccolor = 'blue'}
                            return (
                                <div>
                                    <Tag color={ccolor}>{status}</Tag>
                                </div>
                            )
                        }
                    }
                ],
                formItem: [
                    { 
                        type: "Input",
                        label: "名称", 
                        name: "name", 
                        placeholder: "请输入流程名称"
                    }
                ],
                formSearchCol: 18,
                formRightCol: 6,
            },
            // 表的数据
            data: []
        };
    }
    /** 生命周期挂载完成 */
    componentDidMount(){}

    // 获取子组件实例
    getChildRef = (ref) => {
        this.tableComponent = ref; // 存储子组件
    }
    /** 删除 */
    delete = (id) => {
        this.tableComponent.onHandlerDelete(id)
    }
    
    render(){
        return (
            <Fragment>
                <TableComponent onRef={this.getChildRef} batchButton={true} config={this.state.tableConfig}>
                </TableComponent>
            </Fragment>
        )
    }
}
export default TaskList;